<style>
    .extendimg img {
        width: 60px;
    }

    .extendinfo {
        margin-left: 15px;
        font-size: 13px;
    }

    .extendinfo div {
        margin-top: 2px;
        color: #666;
    }

    .extendinfo .title {
        font-size: 14px;
        font-weight: 600;
    }

    .elist {
        padding-top: 20px;
        padding-bottom: 20px;
        border-bottom: 1px dashed #ccc;
    }
</style>
<div class="rightcontent rc-bg-grey">
    <div class="rc-pagepadding">
        <div class="rc-pannel rc-searchbox">
            <form class="layui-form " method="get">
                <div class="rc-flex-vertical-center rc-searchbox">
                    <div class="layui-inline ">
                        <label class="layui-form-label">应用名称</label>
                        <div class="layui-input-inline ">
                            <input type="text" name="name" placeholder="" value="<?php echo request()->get('name', ''); ?>" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline ">
                        <label class="layui-form-label">扩展标识</label>
                        <div class="layui-input-inline ">
                            <input type="text" name="phone" placeholder="" value="<?php echo request()->get('phone', ''); ?>" autocomplete="off" class="layui-input">
                        </div>
                    </div>


                    <div class="layui-inline">
                        <div class="layui-form-label">
                            <button type="submit" class="layui-btn layui-btn-sm layui-btn-primary"><i class="iconfont">&#xeafe;</i> 搜索</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>


        <div class=" rc-pannel rc-margin-top-default">
            <div class=" rc-pannel-header">
                <div class="rc-flex layui-form toolbar rc-flex-justify-between">
                    <div class=" rc-flex rc-flex-vertical-center ">

                    </div>
                    <div>
                        <a href="javascript:;" class="layui-btn layui-btn-primary layui-btn-sm" id="install"><i class="iconfont">&#xe75f;</i> 安装应用</a>

                    </div>
                </div>


            </div>

            <div class="rc-pannel-body layui-form rc-pagepadding ">
                <?php foreach ($plugins as $plugin) {
                ?>

                    <div class="rc-flex rc-flex-justify-between rc-flex-vertical-center elist">
                        <div class="rc-flex rc-flex-vertical-center rc-flex1">
                            <div class="extendimg">
                                <img src="<?php echo $plugin->logo ? $plugin->logo : '/static/admin/images/logo.png' ?>" />
                            </div>
                            <div class="extendinfo">
                                <div class="rc-text-color-primary title "> <?php echo $plugin->title ?>（<?php echo $plugin->version ?>）</div>
                                <div class="biaoshi">应用目录/标识：<?php echo $plugin->ident ?></div>
                                <div class="desc">描述：<?php echo $plugin->desc ?></div>
                                <div class="author">作者：<?php echo $plugin->author ?> | Email:<?php echo $plugin->email ?> | 微信:<?php echo $plugin->wx ?> | QQ:<?php echo $plugin->qq ?></div>
                            </div>
                        </div>
                        <div class="rc-opbar" style="margin-left:15px">
                            <?php if ($plugin->nextversion) {
                            ?>
                                <a class="info onlineUpgrade" pluginid="<?php echo $plugin->id ?>" href="javascript:;">
                                    <i class="iconfont icon-gengxin"></i> 在线升级

                                    <span class="layui-badge-dot"></span>
                                </a>
                            <?php
                            } ?>


                            <a class="info handleUpgrade" pluginid="<?php echo $plugin->id ?>" href="javascript:;"> <i class="iconfont  icon-update"></i> 手动升级</a>
                            <?php if (file_exists(base_path() . '/plugin/' . $plugin->ident . '/config.ini')) {
                            ?>
                                <a class="configplugin" href-url="/admin/cnf/Plugin/setConfig?id=<?php echo $plugin->id ?>"><i class="iconfont icon-xitong"></i> 配置</a>
                            <?php
                            }
                            ?>
                            <a class="error uninstall" pluginid="<?php echo $plugin->id ?>"><i class="iconfont">&#xe622;</i> 卸载</a>
                        </div>
                    </div>
                <?php
                } ?>

            </div>

            <div class="rc-pannel-footer">
                <div class="pagebar" style="text-align: right;">
                    <?php echo paginator($plugins->total(), 20); ?>
                </div>

            </div>


        </div>

    </div>
</div>
<script type='text/javascript'>
    layui.use(function() {


        $('#install').click(function() {
            layer.open({
                type: 2,
                offset: 'r',
                move: false,
                anim: 'slideLeft', // 从右往左
                area: ['400px', '100%'],
                shade: 0.1,
                title: '安装应用',
                id: 'ID-demo-layer-direction-r',
                content: '/admin/cnf/Plugin/install'
            });
        });



        $('.handleUpgrade').click(function() {

            var pluginid = $(this).attr('pluginid');
            layer.open({
                type: 2,
                offset: 'r',
                move: false,
                anim: 'slideLeft', // 从右往左
                area: ['400px', '100%'],
                shade: 0.1,
                title: '升级应用',
                id: 'ID-demo-layer-direction-r',
                content: '/admin/cnf/Plugin/handleUpgrade?id=' + pluginid
            });

        });

        $('.onlineUpgrade').click(function() {

            var pluginid = $(this).attr('pluginid');
            var loadIndex = layer.load(2);
            var that = $(this);
            $(this).html('<i class="iconfont icon-gengxin"></i> 正在升级...');

            $.ajax({
                url: '/admin/cnf/Plugin/onlineUpgrade?id=' + pluginid, //请求路径
                type: "POST", //请求方式
                success: function(data) {
                    if (data.code == 0) {
                        toastr_success('升级成功', function() {
                            window.location.reload();
                        });

                    } else {
                        toastr_error(data.message);
                        that.html('<i class="iconfont icon-gengxin"></i>在线升级 <span class="layui-badge-dot"></span>');
                    }
                },
                error: function() {
                    that.html('<i class="iconfont icon-gengxin"></i>在线升级 <span class="layui-badge-dot"></span>');
                },
                complete: function() {
                    layer.closeAll();
                }

            });



        });



        $('.uninstall').click(function() {
            var pluginid = $(this).attr('pluginid');
            layer.confirm('卸载后连插件文件夹一同删掉已经数据库中的插件信息，确定要卸载么？', {
                btn: ['确定', '关闭'] //按钮
            }, function() {
                $.ajax({
                    url: '/admin/cnf/Plugin/unInstall', //请求路径
                    type: "POST", //请求方式
                    data: {
                        id: pluginid
                    }, // 默认写法
                    success: function(data) {
                        if (data.code == 0) {
                            window.location.reload();
                        } else {
                            toastr_error(data.message);
                        }
                    },
                    error: function() {

                    },

                });
            }, function() {



            });

        });

        $('.configplugin').click(function() {
            var url = $(this).attr('href-url');
            layer.open({
                type: 2,
                offset: 'r',
                move: false,
                anim: 'slideLeft', // 从右往左
                area: ['600px', '100%'],
                shade: 0.1,
                title: '配置插件',
                id: 'ID-demo-layer-direction-r',
                content: url
            });
        });
    });
</script>